home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / NeoDemo / Source / CNeoDemoApp.cp < prev    next >
Encoding:
Text File  |  1994-08-07  |  5.4 KB  |  234 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CNeoDemoApp.c
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *  Copyright © 1992 NeoLogic Systems.  All rights reserved.
  7.  *
  8.  *****/
  9.  
  10. #include "NeoTypes.h"
  11. #include CNeoMetaClassH
  12. #include <Commands.h>
  13. #include <CDesktop.h>
  14. #include <CBartender.h>
  15. #include <CWindow.h>
  16. #include <CList.h>
  17. #include "CNeoDLOGDialog.h"
  18. #include "CNeoDemoDoc.h"
  19. #include "CNeoDemoApp.h"
  20. #include "CNDCamera.h"
  21. #include "CNDImagePICT.h"
  22. #include "CNDImageTIFF.h"
  23. #include "CNDImageGIF.h"
  24.  
  25. extern    OSType    gSignature;
  26.  
  27. extern CDesktop        *gDesktop;            // The visible Desktop
  28. extern CBartender    *gBartender;        // Manages all menus
  29.  
  30. int main(void)
  31. {
  32.     CNeoDemoApp *    app;
  33.  
  34.     app = new CNeoDemoApp();
  35.     app->Run();
  36.     app->Exit();
  37.  
  38.     return 0;
  39. }
  40.  
  41. /***
  42.  * CNeoDemoApp
  43.  *
  44.  *    Initialize the application. Your initialization method should
  45.  *    at least call the inherited method. If your application class
  46.  *    defines its own instance variables or global variables, this
  47.  *    is a good place to initialize them.
  48.  *
  49.  ***/
  50.  
  51. CNeoDemoApp::CNeoDemoApp(void)
  52. #ifdef qNeoShare
  53.     : CNeoAppShareTCL(kNeoDemoSig, kNeoDemoFileType, kExtraMasters, kRainyDayFund, kCriticalBalance, kToolboxBalance)
  54. #else
  55.     : CNeoAppTCL()
  56. #endif
  57. {
  58.     CNeoMetaClass *    meta;
  59.  
  60. #if defined(__TCL_DEBUG__) && !defined(TCL_USE_PP_EXCEPTIONS)
  61. //    _gTCLBreakFailure = TRUE;
  62. #endif
  63.  
  64.     IApplication(kNeoExtraMasters, kNeoRainyDayFund, kNeoCriticalBalance, kNeoToolboxBalance);
  65.  
  66.     // Add CNDImage class to metaclass table
  67.     meta = new CNeoMetaClass(kNDImageID, kNeoPersistID, "\pCNDImage");
  68.  
  69.     // Add CNDImagePICT class to metaclass table
  70.     meta = new CNeoMetaClass(kNDImagePICTID, kNDImageID, "\pCNDImagePICT", CNDImagePICT::New);
  71.  
  72.     // Add CNDImageTIFF class to metaclass table
  73.     meta = new CNeoMetaClass(kNDImageTIFFID, kNDImageID, "\pCNDImageTIFF", CNDImageTIFF::New);
  74.  
  75.     // Add CNDImageGIF class to metaclass table
  76.     meta = new CNeoMetaClass(kNDImageGIFID, kNDImageID, "\pCNDImageGIF", CNDImageGIF::New);
  77.  
  78.     // Add CNDCamera class to metaclass table
  79.     meta = new CNeoMetaClass(kNDCameraID, kNeoPersistID, "\pCNDCamera", CNDCamera::New);
  80.  
  81.     CNeoPersist::FCacheSize = 0x40000;    // Give the object cache a quarter meg to play with.
  82. }
  83.  
  84. /***
  85.  * SetUpFileParameters
  86.  *
  87.  *    In this routine, you specify the kinds of files your
  88.  *    application opens.
  89.  *
  90.  *
  91.  ***/
  92.  
  93. void CNeoDemoApp::SetUpFileParameters(void)
  94.  
  95. {
  96.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  97.  
  98.         /**
  99.         **    sfNumTypes is the number of file types
  100.         **    your application knows about.
  101.         **    sfFileTypes[] is an array of file types.
  102.         **    You can define up to 4 file types in
  103.         **    sfFileTypes[].
  104.         **
  105.         **/
  106.  
  107.     sfNumTypes = 1;
  108.     sfFileTypes[0] = kNeoDemoFileType;            /* Neo Demo file type */
  109.  
  110.         /**
  111.         **    Although it's not an instance variable,
  112.         **    this method is a good place to set the
  113.         **    gSignature global variable. Set this global
  114.         **    to your application's signature. You'll use it
  115.         **    to create a file (see CFile::CreateNew()).
  116.         **
  117.         **/
  118.  
  119.     gSignature = kNeoDemoSig;        /* set application signature */
  120. }
  121.  
  122. /***
  123.  * createDocument
  124.  *
  125.  *    The user chose New from the File menu.
  126.  *    In this method, you need to create a document and send it
  127.  *    a NewFile() message.
  128.  *
  129.  ***/
  130. CNeoDoc    *CNeoDemoApp::createDocument(void)
  131. {
  132.     CNeoDemoDoc    *    document = nil;
  133.  
  134.     NEOTRY
  135.     {
  136.         document = new CNeoDemoDoc(this, kNotPrintable, TRUE, FALSE);
  137.  
  138.             /**
  139.             **    Send the document a NewFile() message.
  140.             **    The document will open a window, and
  141.             **    set up the heart of the application.
  142.             **
  143.             **/
  144.  
  145.         document->NewFile();
  146.     }
  147.  
  148.     NEOCATCH
  149.     {
  150.         /*
  151.         * This exception handler gets executed if a failure occurred
  152.         * anywhere within the scope of the TRY block above. Since
  153.         * this indicates that a new doc could not be created, we
  154.         * check if an object had been allocated and if it has, send
  155.         * it a unrefer message. The exception will propagate up to
  156.         * CSwitchboard's exception handler, which handles displaying
  157.         * an error alert.
  158.         */
  159.  
  160.         if (document) {
  161.             delete document;
  162.             document = nil;
  163.         }
  164.     }
  165.     NEOENDTRY;
  166.  
  167.     return document;
  168. }
  169.  
  170. /***
  171.  * OpenDocument
  172.  *
  173.  *    The user chose Open… from the File menu.
  174.  *    In this method you need to create a document
  175.  *    and send it an OpenFile() message.
  176.  *
  177.  *    The macSFReply is a good SFReply record that contains
  178.  *    the name and vRefNum of the file the user chose to
  179.  *    open.
  180.  *
  181.  ***/
  182.  
  183. void CNeoDemoApp::OpenDocument(SFReply *macSFReply)
  184. {
  185.     Boolean            remote;
  186.     long            procID;
  187.     FSSpec            fsSpec;
  188.     CNeoDemoDoc *    document    = nil;
  189.  
  190.     NEOTRY
  191.     {
  192.         // Our parent will check to see if this is a document we have already opened.
  193.         // If we find the file already open by the app, then fDocument will refer to it.
  194.         // If the file is opened but not by this app, then the parent will signal a failure.
  195.         inherited::OpenDocument(macSFReply);
  196.         if (fDocument)
  197.             return;
  198.  
  199. #ifdef qNeoShare
  200.         remote = fOpeningRemote;
  201. #else
  202.         remote = FALSE;
  203. #endif
  204.  
  205.         document = new CNeoDemoDoc(this, TRUE, FALSE, remote);
  206.  
  207.         /**
  208.         **    Send the document an OpenFile() message.
  209.         **    The document will open a window, open
  210.         **    the file specified in the macSFReply record,
  211.         **    and display it in its window.
  212.         **
  213.         **/
  214.         document->OpenFile(macSFReply);
  215.     }
  216.  
  217.     NEOCATCH
  218.     {
  219.         /*
  220.         * This exception handler gets executed if a failure occurred
  221.         * anywhere within the scope of the TRY block above. Since
  222.         * this indicates that the document could not be opened, we
  223.         * send it a unrefer message. The exception will propagate up to
  224.         * CSwitchboard's exception handler, which handles displaying
  225.         * an error alert.
  226.         */
  227.  
  228.         if (document)
  229.             delete document;
  230.     }
  231.     NEOENDTRY;
  232. }
  233.  
  234.